﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Data;
using VIT.DataHelper.DataAccess;
using System.Data.SqlClient;


namespace VIT.Web.Modules.Logo
{
    public class LogoProvider
    {
        #region Properties
        public int Id { get; set; }
        public string LanguageId { get; set; }

        SQLSupport sqlSupport = new SQLSupport();
        #endregion

        public void getLogos(Dictionary<string, string> param, ref int Width, ref int Height, ref string Style, ref string FileName, ref string Title, ref string Link)
        {
            string Position;
            try { Position = param["Position"]; }
            catch { Position = string.Empty; }
            try { Style = param["Style"]; }
            catch { Style = String.Empty; }

            if (Position.Length > 0)
            {
                string strQuery = "select top 1 FullLogo, Link, FileName, Title From Logo Where LanguageID=@LanguageID and PositionId=@PositionId and Type='Image' and Published=1";
                SqlParameter LanguageId = new SqlParameter("@LanguageID", this.LanguageId);
                SqlParameter PositionId = new SqlParameter("@PositionId", Position);
                DataTable table = sqlSupport.ExecuteDataset(false, strQuery, LanguageId, PositionId).Tables[0];

                if (table.Rows.Count > 0)
                {
                    try { Width = int.Parse(param["Width"]); }
                    catch { Width = 0; }
                    try { Height = int.Parse(param["Height"]); }
                    catch { Height = 0; }
                    if (Width > 0 || Height > 0)
                    {
                        Title = table.Rows[0]["Title"].ToString();
                        FileName = table.Rows[0]["FileName"].ToString();
                        Link = table.Rows[0]["Link"].ToString();
                    }
                }
            }
        }
    }
}
